package com.ruoyi.ctcx.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ctcx.domain.ro.InsuranceQueryParam;
import com.ruoyi.ctcx.domain.vo.TbInsuranceContractCoinsuranceVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ctcx.domain.TbInsuranceContractCoinsurance;
import com.ruoyi.ctcx.service.ITbInsuranceContractCoinsuranceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 保险合同共保信息Controller
 * 
 * @author ruoyi
 * @date 2024-11-21
 */
@RestController
@RequestMapping("/insurance/coinsurance")
public class TbInsuranceContractCoinsuranceController extends BaseController
{
    @Autowired
    private ITbInsuranceContractCoinsuranceService tbInsuranceContractCoinsuranceService;

    /**
     * 查询保险合同共保信息列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:coinsurance:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbInsuranceContractCoinsurance tbInsuranceContractCoinsurance)
    {
        startPage();
        List<TbInsuranceContractCoinsuranceVo> list = tbInsuranceContractCoinsuranceService.selectTbInsuranceContractCoinsuranceList(tbInsuranceContractCoinsurance);
        return getDataTable(list);
    }

    /**
     * 导出保险合同共保信息列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:coinsurance:export')")
    @Log(title = "保险合同共保信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbInsuranceContractCoinsurance tbInsuranceContractCoinsurance)
    {
        List<TbInsuranceContractCoinsuranceVo> list = tbInsuranceContractCoinsuranceService.selectTbInsuranceContractCoinsuranceList(tbInsuranceContractCoinsurance);
        ExcelUtil<TbInsuranceContractCoinsuranceVo> util = new ExcelUtil<TbInsuranceContractCoinsuranceVo>(TbInsuranceContractCoinsuranceVo.class);
        util.exportExcel(response, list, "保险合同共保信息数据");
    }

    /**
     * 获取保险合同共保信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('insurance:coinsurance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbInsuranceContractCoinsuranceService.selectTbInsuranceContractCoinsuranceById(id));
    }

    @GetMapping("/getContractCoinsuranceList")
    public AjaxResult getContractCoinsuranceList(InsuranceQueryParam insuranceQueryParam)
    {
        TbInsuranceContractCoinsurance tbInsuranceContractCoinsurance = new TbInsuranceContractCoinsurance();
        tbInsuranceContractCoinsurance.setInsureId(insuranceQueryParam.getInsureId());
        List<TbInsuranceContractCoinsuranceVo> list = tbInsuranceContractCoinsuranceService.selectTbInsuranceContractCoinsuranceList(tbInsuranceContractCoinsurance);
        return success(list);
    }

    /**
     * 新增保险合同共保信息
     */
    @PreAuthorize("@ss.hasPermi('insurance:coinsurance:add')")
    @Log(title = "保险合同共保信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbInsuranceContractCoinsurance tbInsuranceContractCoinsurance)
    {
        tbInsuranceContractCoinsurance.setCreateBy(getUsername());
        return toAjax(tbInsuranceContractCoinsuranceService.insertTbInsuranceContractCoinsurance(tbInsuranceContractCoinsurance));
    }

    /**
     * 修改保险合同共保信息
     */
    @PreAuthorize("@ss.hasPermi('insurance:coinsurance:edit')")
    @Log(title = "保险合同共保信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbInsuranceContractCoinsurance tbInsuranceContractCoinsurance)
    {
        tbInsuranceContractCoinsurance.setUpdateBy(getUsername());
        return toAjax(tbInsuranceContractCoinsuranceService.updateTbInsuranceContractCoinsurance(tbInsuranceContractCoinsurance));
    }

    /**
     * 删除保险合同共保信息
     */
    @PreAuthorize("@ss.hasPermi('insurance:coinsurance:remove')")
    @Log(title = "保险合同共保信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbInsuranceContractCoinsuranceService.deleteTbInsuranceContractCoinsuranceByIds(ids));
    }
}
